import { useStore } from "@/store/user";
import { Directive } from 'vue';

export const permission: Directive = {
    mounted(el, binding) {
        const { value } = binding
        const all_permission = "*";
        const user = useStore()
        const permissions: Array<string> = user.permissions

        if (value && value instanceof Array && value.length > 0) {
            const permissionFlag = value
            console.log("🚀 ~ file: hasPermi.ts ~ line 12 ~ mounted ~ permissionFlag", permissionFlag)

            const hasPermissions = permissions.some(permission => {
                return all_permission === permission || permissionFlag.includes(permission)
            })

            if (!hasPermissions) {
                console.log("🚀 没有对应的权限")
                // el.parentNode && el.parentNode.removeChild(el)
            }
        } else {
            throw new Error(`请设置操作权限标签值`)
        }
    }
}
